// this file is loaded by the assembler to get information on converting assembly instructions
// 8086 assembly / machine code translation

// This is not a complete instruction set so if you can help complete it, it would be a great help.

#symbols

// Binary |	register	 

// 16 bit registers
000		ax
001		cx
010		dx
011		bx
100		sp
101		bp
110		si
111		di

// _reg16, some instructions refer to a 16 bit register with a 2 bit value excluding the registers (sp, bp, si, di)
00		_ax
01		_cx
10		_dx
11		_bx
// These refer to ax, bx, cx, dx but just use 2 bit values instead.  These are used in some opcodes like xchg _reg16, _reg16

// 8 bit registers
000		al
001		cl
010		dl
011		bl
100		ah
101		ch
110		dh
111		bh

// segment registers
00111		es
01111		cs
10111		ss
11111		ds


#defines

reg8 = al, bl, cl, dl, ah, bh, ch, dh
reg16 = ax, bx, cx, dx, sp, bp, si, di
_reg16 = _ax, _bx, _cx, _dx  
seg = es, cs, ss, ds 

// i8 and i16 are defined in the assembler program
// mem8 and mem16 are undefined at present

// i8 -> 8 bit immediate value
// i16 -> 16 bit immediate value
// for i16, the bytes need to be swapped.  This is automatically done by the assembler.
// reg8 -> 8 bit register
// reg16 -> 16 bit register
// mem8 -> address to an 8 bit variable
// mem16 -> address to a 16 bit variable

#opcode // indicate beginning of opcode definitions

// Binary |		opcode | 	operands |	machine code size

000			pop		seg		// 1 byte
000010110011		or		reg16, reg16	// 2 bytes
000011000011		or		reg8, reg8	// 2 bytes
		
0011001011		xor		reg8, reg8	// 2 bytes
0011001111		xor		reg16, reg16	// 2 bytes
00110111		aaa				// 1 byte
00111111		aas				// 1 byte
01000			inc		reg16		// 1 byte
01001			dec		reg16		// 1 byte
01011			pop		reg16		// 1 byte
01100000		pusha				// 1 byte
01100001		popa				// 1 byte
01101000		push		i16		// 3 bytes
01101010		push		i8		// 2 bytes


01110000		jo		i8		// 2 bytes
01110001		jno		i8		// 2 bytes

01110010		jb		i8		// 2 bytes
01110010		jc		i8		// 2 bytes
01110010		jnae		i8		// 2 bytes

// 0x72
01110011		jnb		i8		// 2 bytes
01110011		jnc		i8		// 2 bytes
01110011		jae		i8		// 2 bytes, jae, jnc, jnb are the same
01110100		je		i8		// 2 bytes
01110100		jz		i8		// 2 bytes, same as je
01110101		jnz		i8		// 2 bytes
01110101		jne		i8		// 2 bytes
01110110		jna		i8		// 2 bytes
01110111		ja		i8		// 2 bytes
01110111		jnbe		i8		// 2 bytes, same as ja
01111001		jns		i8		// 2 bytes
01111000		js		i8		// 2 bytes
01111010		jp		i8		// 2 bytes
01111011		jnp		i8		// 2 bytes
01111011		jpo		i8		// 2 bytes, same as jnp
// 0x7B

01111100		jl		i8		// 2 bytes
01111100		jnge		i8		// 2 bytes
01111101		jnl		i8		// 2 bytes
01111110		jng		i8		// 2 bytes
01111110		jle		i8		// 2 bytes
01111111		jg		i8		// 2 bytes


10010000		nop				// 1 byte
1001			xchg		_reg16, _reg16	// 1 byte
1000011011		xchg		reg8, reg8	// 2 bytes
10011100		pushf				// 1 byte
10011101		popf				// 1 byte
10011101		sahf				// 1 byte, same as popf
10011111		lahf				// 1 byte
10100100		movsb				// 1 byte
10100101		movsw				// 1 byte
10100110		cmpsb				// 1 byte
10100111		cmpsw				// 1 byte
10101010		stosb				// 1 byte
10101011		stosw				// 1 byte
10101100		lodsb				// 1 byte
10101110		scasb				// 1 byte
10101111		scasw				// 1 byte

10110			mov		reg8, i8	// 2 bytes
10111			mov		reg16, i16	// 3 bytes
11000011		ret				// 1 byte

11001101		int		i8		// 2 bytes
11001110		into				// 1 byte
11001111		iret				// 1 byte

1101010000001010	aam				// 2 byte
1101010100001010	aad				// 2 byte

11010111		xlat				// 1 byte
11101000		call		i8		// 2 bytes

11101011		jmp		i8		// 2 bytes
11100011		jcxz		i8		// 2 bytes

11110010		repne				// 1 byte	
11110010		repnz				// 1 byte	
11110011		rep				// 1 byte	
11110011		repe				// 1 byte	
11110011		repz				// 1 byte	

11110100		hlt				// 1 byte
1111011011010		not		reg8		// 2 byte
1111011011011		neg		reg8		// 2 bytes
1111011111011		neg		reg16		// 2 bytes
11111000		clc				// 1 byte
11111001		stc				// 1 byte
11111010		cli				// 1 byte
11111011		sti				// 1 byte
11111100		cld				// 1 byte
11111101		std				// 1 byte

1111111011000		inc		reg8		// 2 bytes
1111111011001		dec		reg8		// 2 bytes



#examples: // indicate that the following information is ignored by the assembler
// this section is to help you understand how the process works.


// Binary-Hex |				assembly

10111+000 + 00010011 00000000 		mov	ax,13h
0xB81300

10110+100 + 00010011	 		mov	al,13h
0xB813

11001101 + 00010000			int 	10h
0xCD10

01101000 + 00000000 1010000 		push 	A000h
0x6800A0

11101011 + 11101111			jmp -10h
0xEBEF

10111+010 + 11001000 00000011		mov dx,03C8h
0xBAC803

01011+000				pop ax
0x58

000+00111				pop es
0x07

000+10111				pop ss
0x17

000+11111				pop ds
0x1F

// here is some stuff that is not completely understood

00110100		xor		al, i8		// 2 bytes
00111100		cmp		al, i8		// 2 bytes
00111101		cmp		ax, i16		// 3 bytes

01000000000111100	cmp		ah, i8		// 3 bytes

xor al,1 ; 34 01
xor cl,1 ; 80 F1 01
xor ah,1 ; 80 F4 01
xor ch,1 ; 80 F5 01
xor ax,1 ; 35 01 00
cmp ax,ax ; 3B C0
cmp ax,bx ; 3B C3
cmp cx,1 ; 83 F9 01

call 100h ; E8 FD FF
call 1100h ; E8 FA 0F
jmp 1100h ; E9 F7 0F
jmp 100h ; EB F5

push es ; 06

